package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author
 * @Date 2024/5/18 19:20
 * @Description:
 */
@RestController
@RequestMapping("/admin/order/")
@Slf4j
@Api(tags = "订单管理")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("/conditionSearch")
    @ApiOperation("分页查询")
    public Result<PageResult> getOrderList(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("查询订单列表");
        PageResult pageResult= orderService.getOrderList(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/statistics")
    @ApiOperation("订单统计")
    public Result<OrderStatisticsVO> getOrderStatistics(){
        log.info("查询订单统计");
        OrderStatisticsVO orderStatisticsVO=orderService.getClassCount();
        return Result.success(orderStatisticsVO);
    }
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("订单拒绝:{}",ordersRejectionDTO.getId());
        orderService.update(ordersRejectionDTO);
        return Result.success();
    }
    @PutMapping("confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("订单:{}已被接单",ordersConfirmDTO.getId());
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }
    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrderDetails(@PathVariable("id") Long id){
        log.info("查询订单详情:{}",id);
        OrderVO orderVO=orderService.getOrderDetails(id);
     return Result.success(orderVO);
    }
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id") Long id){
        log.info("订单:{}开始派送配送",id);
        orderService.delivery(id);
        return Result.success();
    }
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable("id") Long id){
        log.info("订单:{}完成配送",id);
        orderService.complete(id);
        return Result.success();
    }
    @PutMapping("cancel/{id}")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("订单:{}已被取消",ordersCancelDTO.getId());
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }


}
